(function() {

	Nokia.extend(Nokia.animation,
		{
			animate: function(selector) {
				var args = Array.prototype.slice.call(arguments, 1);

				Nokia.animation.applyTransition(function() {
					var scope = jQuery(selector);
					scope.css.apply(scope, args);
				});
			},

			fadeIn: function(selector) {
				Nokia.animation.applyTransition(function() {
					jQuery(selector)[0].style.display = 'block';
				});
			},

			fadeOut: function(selector) {
				Nokia.animation.applyTransition(function() {
					jQuery(selector)[0].style.display = 'none';
				});
			},

			slide: function(selector) {
				var el = jQuery(selector);
				var width = el.outerWidth();
				var oldHidder = jQuery('.over[selector=' + selector + ']');
				var hidderExists = oldHidder.size() > 0;

				if (!hidderExists) {
					var hidder = jQuery('<div class="over" selector="' + selector + '"></div>');
					hidder.appendTo('body');
				} else {
					hidder = oldHidder;
				}

				if ( hidder.is(':hidden') ) {

					hidder.css({
						top: el.offset().top,
						left: el.offset().left,
						height: el.outerHeight(),
						width: 0,
						display: 'block'
					});

					Nokia.animation.animate(hidder, {width: width});
				} else {
					Nokia.animation.animate(oldHidder, {width: 0, display: 'none'});
				}
			},

			prepareForTransition: function(transitionMode) {
				if (window.widget) {
					window.widget.prepareForTransition(transitionMode || 'fade');
				}
			},

			performTransition: function() {
				if (window.widget) {
					window.widget.performTransition();
				}
			},

			applyTransition: function(fn, scope, arguments) {
				Nokia.animation.prepareForTransition();

				fn.apply(scope || this, arguments);

				Nokia.animation.performTransition();
			}

		}
	);
})();